#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCheckBox>
#include <TouchButton.h>
#include "transparentlistview.h"
#include "models/videomodel.h"
#include <QStyledItemDelegate>

class VideoItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    explicit VideoItemDelegate(QObject* parent = nullptr);
    void paint(QPainter* painter, const QStyleOptionViewItem& option,
               const QModelIndex& index) const override;
private:
    QPixmap m_checkedPixmap;
    QPixmap m_uncheckedPixmap;
};

class VideoWidget : public QWidget
{
    Q_OBJECT
public:
    explicit VideoWidget(QWidget *parent = nullptr);
    bool isSelectMode();

protected:
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void resizeEvent(QResizeEvent* event) override;
    void setVisible(bool visible) override;

private slots:
    void onSelectButtonClicked();
    void onDeleteButtonClicked();
    void onCancelButtonClicked();
    void onSelectAllClicked();

private:
    void initUI();
    void updateSelectAllCheckBoxState();

private:
    TransparentListView* m_videoListView;
    TouchButton* m_selectButton;
    TouchButton* m_deleteButton;
    TouchButton* m_cancelButton;
    QCheckBox* m_selectAllCheckBox;
    bool m_isSelectMode;
    QRubberBand* m_rubberBand;
    QPoint m_rubberBandOrigin;
    bool m_initialClickState;
    bool m_initialStateSet;
    int m_initialScrollOffset;
    QMap<int, bool> m_itemOriginalStates;
    QPoint m_pressPos;
    bool m_hasMoved = false;
    QVBoxLayout* m_listLayout = NULL;
};

#endif // VIDEOWIDGET_H
